package com.lvchenglong.mybatis;

import com.lvchenglong.mybatis.domain.Blog;
import com.lvchenglong.mybatis.mapper.BlogXMLMapper;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

@SpringBootApplication
@MapperScan("com.lvchenglong.mybatis.mapper")
public class MybatisApplication implements ApplicationContextAware {

    @Autowired
    private BlogXMLMapper mapper;

    private static ApplicationContext applicationContext;

    public static void main(String[] args) {
        SpringApplication.run(MybatisApplication.class, args);
        MybatisApplication app = applicationContext.getBean(MybatisApplication.class);
        Blog blog = app.mapper.selectBlog(101);
        System.out.println(blog.getName());
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

}
